<template>
  <div class="flex flex_column">
    <el-dialog
      append-to-body
      title="生产领料"
      :visible.sync="isVisible"
      :close-on-click-modal="false"
      custom-class="bodyNoPadDialog bigDialog"
      width="80%"
      @close="closeMarDialog"
      @open="opens"
    >
      <div class="dialogDody marDialog flex flex_column">
        <div class="btnCon flex flex_between">
          <div>
            <el-button
              slot="append"
              :loading="marLoading"
              type="primary"
              size="small"
              icon="el-icon-plus"
              :disabled="marLoading"
              element-loading-spinner="el-icon-loading"
              @click="newAddClick"
            >
              新建
            </el-button>
          </div>
          <!--      搜索框-->
          <div class="search">
            <el-input
              v-model="materalSearch.likeWords"
              placeholder="输入关键字"
              size="small"
            >
              <el-button
                slot="append"
                :loading="marLoading"
                type="primary"
                icon="el-icon-search"
                :disabled="marLoading"
                element-loading-spinner="el-icon-loading"
                @click="MarterdialogShow"
              >
                搜索
              </el-button>
            </el-input>
          </div>
        </div>
        <!-- 表格区域       -->
        <div class="tableCon">
          <el-table :data="dataList" border style="width: 100%">
            <el-table-column
                  prop="getMaterialBillNo"
                  label="领料单号"
                  width="180"
                />
                <el-table-column
                  label="领料类型"
                  prop="getMaterialTypeName"
                  show-overflow-tooltip
                  min-width="100"
                />
                <el-table-column
                  label="单据状态"
                  prop="getMaterialBillStateName"
                  show-overflow-tooltip
                  min-width="100"
                />
                <el-table-column
                  label="出库状态"
                  prop="outStockStateName"
                  min-width="100"
                />
                <el-table-column
                  label="关联单据"
                  prop="produceTaskBillNo"
                  min-width="150"
                />
                <el-table-column
                  label="明细项数"
                  prop="getMaterialKindCount"
                  show-overflow-tooltip
                  min-width="90"
                >
                </el-table-column>
                <el-table-column
                  label="领料设备"
                  prop="equipmentName"
                  min-width="80"
                />
                <el-table-column
                  label="领料人员"
                  prop="getMaterialPersonName"
                  min-width="80"
                />
                <el-table-column
                  label="创建人员"
                  prop="createPersonName"
                  min-width="80"
                />
                <el-table-column
                  label="创建时间"
                  prop="createDate"
                  min-width="150"
                />
                <el-table-column
                  label="备注"
                  show-overflow-tooltip
                  min-width="150"
                  prop="getMaterialRemark"
                >
                </el-table-column>
                <el-table-column
          label="操作"
          width="70px"
          fixed="right"
          align="center"
        >
          <template slot-scope="scope">
            <div>
              <el-popover
                :ref="`popover-${scope.$index}`"
                placement="bottom-end"
                popper-class="tableOp"
                width="160"
                :popper-options="{
                    boundariesElement: 'opBox',
                    removeOnDestroy: true,
                  }"
                trigger="click"
              >
                <div class="operation">
                  <ul>
                    <li @click="handleClick(scope.row)">
                      查看
                    </li>
                    <li v-show="scope.row.getMaterialBillState === 0" @click="handleUpdata(scope.row)">
                      修改
                    </li>
                  </ul>
                  <ul>
                    <li v-show="scope.row.getMaterialBillState === 0" @click="handleConfirm(scope.row)">
                      确认
                    </li>
                    <li v-show="scope.row.getMaterialBillState === 1 && scope.row.outStockState === 0 " @click="handleDone(scope.row)">
                      作废
                    </li>
                    <li v-show="scope.row.getMaterialBillState === 2 " @click="handleCopy(scope.row)">
                      复制
                    </li>
                  </ul>
                  <ul>
                    <li v-show="scope.row.getMaterialBillState === 0" @click="handleDelete(scope.row)">
                      删除
                    </li>
                  </ul>
                </div>
                <div slot="reference" class="opBox pointer">
                  <span class="el-icon-more c_3F61F1" />
                </div>
              </el-popover>
            </div>
          </template>
        </el-table-column>
          </el-table>
        </div>
        <!-- 人员寻找弹框   -->
        <per-redio-dialog
          :per-visible.sync="isperShow"
          @getEmployee="getEmployee"
        />
        <el-dialog
          :title="tname"
          :visible.sync="isAddProduct"
          :close-on-click-modal="false"
          custom-class="bodyNoPadDialog bigDialog"
          append-to-body
          width="85%"
          @close="closeDialog"
          @open="openCp"
        >
          <div class="dialogDody">
            <div class="subTip">
              <span class="mr15"
                ><span class="mr5">领料单号：</span
                >{{ ProductForm.getMaterialBillNo || "系统自动生成" }}</span
              >
              <span class="mr15"
                ><span class="mr5">创建日期：</span
                >{{
                  ProductForm.createDate || dayjs().format("YYYY-MM-DD")
                }}</span
              >
              <span class="mr15"
                ><span class="mr5">创建人员：</span
                >{{ opsid != 1 ? ProductForm.createPersonName : name }}</span
              >
              <span class="mr15"
                ><span class="mr5">客户单号：</span
                >{{ ProductForm.customerBillNo }}</span
              >
            </div>
            <div class="addWuliaoBox">
              <el-form
                ref="ProductForm"
                :model="ProductForm"
                :rules="rules"
                label-width="110px"
                label-position="left"
                class="dialogForm dialogInlineForm"
                :disabled="canDiable"
              >
                <el-row>
                  <el-col :span="8">
                    <el-form-item label="领料类型" prop="purchaseType">
                      <el-select
                        filterable
                        v-model="ProductForm.getMaterialType"
                        placeholder="领料类型"
                        size="mini"
                        filterable
                      >
                        <el-option
                          v-for="item in purchaseTypes"
                          :key="item.dicValueID"
                          :label="item.dicValueDesc"
                          :value="item.dicValueCode"
                        />
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item label="关联单据">
                      <div class="flex flex_center">
                        <div class="flex1">
                          <el-input
                            v-model="ProductForm.produceTaskBillNo"
                            placeholder="选择生产单"
                            size="mini"
                            disabled
                          />
                        </div>
                        <div class="ml10">
                          <selectProductOrder />
                        </div>
                      </div>
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item label="领料人员" prop="getMaterialPersonName">
                      <div class="flex flex_center">
                        <div class="flex1">
                          <el-input
                            v-model="ProductForm.getMaterialPersonName"
                            size="mini"
                            placeholder="请选择人员"
                          >
                            <el-button
                              slot="append"
                              icon="el-icon-user"
                              @click="isperShow = true"
                            />
                          </el-input>
                        </div></div
                    ></el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="8">
                    <el-form-item label="领料设备" prop="equipmentNo">
                      <el-select
                        filterable
                        v-model="ProductForm.equipmentNo"
                        placeholder="领料设备"
                        disabled
                        filterable
                        size="mini"
                        @change="supplierChange"
                      >
                        <el-option
                          v-for="item in equipmentList"
                          :key="item.equipmentNo"
                          :label="item.equipmentName"
                          :value="item.equipmentNo"
                        />
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item label="订单单号" prop="xieYiShuHao">
                      <div class="flex flex_center">
                        <div class="flex1">
                          <el-input
                            v-model="ProductForm.xieYiShuHao"
                            size="mini"
                            disabled
                          >
                          </el-input>
                        </div></div
                    ></el-form-item>
                  </el-col>
                  <!-- <el-col :span="8">
                    <el-form-item label="协议书号" prop="productCode">
                      <div class="flex flex_center">
                        <div class="flex1">
                          <el-input
                            v-model="ProductForm.productCode"
                            size="mini"
                            disabled
                          >
                          </el-input>
                        </div></div
                    ></el-form-item>
                  </el-col> -->
                  <el-col :span="8">
                    <el-form-item label="产品名称" prop="orderProductName">
                      <div class="flex flex_center">
                        <div class="flex1">
                          <el-input
                            v-model="ProductForm.orderProductName"
                            size="mini"
                            disabled
                          >
                          </el-input>
                        </div></div
                    ></el-form-item>
                  </el-col>
                </el-row>
                <el-row>

                  <el-col :span="8">
                    <el-form-item label="版本版面" prop="productVersion">
                      <div class="flex flex_center">
                        <div class="flex1">
                          <el-input
                            v-model="ProductForm.productVersion"
                            size="mini"
                            disabled
                          >
                          </el-input>
                        </div></div
                    ></el-form-item>
                  </el-col>
                </el-row>
                <el-form-item label="领料备注" class="inlineText">
                  <el-input
                    v-model="ProductForm.getMaterialRemark"
                    type="textarea"
                    :rows="1"
                    placeholder="领料备注"
                    size="mini"
                    clearable
                  />
                </el-form-item>
              </el-form>
              <div class="tableBox">
                <div class="tt flex flex_between">
                  <span class="fw">领料明细</span>
                  <span
                    v-if="!canDiable"
                    class="c_3F61F1 mr15 pointer"
                    @click="isSemidialog = true"
                    ><i class="el-icon-plus mr5" /> 新增</span
                  >
                </div>
                <div ref="bigdialogTable" class="bigdialogTbCon">
                  <el-table
                    :data="ProductForm.mxDataList"
                    border
                    style="width: 100%"
                  >
                    <el-table-column
                      prop="goodsCode"
                      label="物料编号"
                      width="120"
                    />
                    <el-table-column
                      label="物料类型"
                      prop="goodsCategoryName"
                      show-overflow-tooltip
                      min-width="100"
                    />
                    <el-table-column
                      label="供应商"
                      prop="supplierName"
                      show-overflow-tooltip
                      min-width="100"
                    />
                    <el-table-column
                      label="物料名称"
                      prop="goodsName"
                      min-width="100"
                    />
                    <el-table-column
                      label="规格型号"
                      prop="stockGoodsName"
                      min-width="100"
                    />
                    <el-table-column
                  label="领料数量"
                  prop="applyGetQuantity"
                  show-overflow-tooltip
                  min-width="90"

                >
                <template slot-scope="{row}">
                  <el-input
                   v-if="ProductForm.outStockState ==0 || ProductForm.outStockState ==3"
                    v-model.number="row.applyGetQuantity"
                    :disabled="canDiable"
                    placeholder="请输入"
                    size="mini"
                    onkeyup="value=value.replace(/[^\d]/g,'')"
                  />
                  <el-input
                  v-else
                    v-model.number="row.receiveQuantity"
                    placeholder="请输入"
                    disabled
                    size="mini"
                    onkeyup="value=value.replace(/[^\d]/g,'')"
                  />
                </template>
                </el-table-column>
                    <el-table-column
                      label="单位"
                      prop="goodsUnitName"
                      min-width="80"
                    />
                    <el-table-column
                      label="库存数量"
                      prop="stockQuantity"
                      min-width="80"
                    />
                    <el-table-column
                      label="备注"
                      show-overflow-tooltip
                      min-width="150"
                      prop="getMaterialRemark"
                    >
                      <template slot-scope="{ row }">
                        <el-input
                          v-model="row.getMaterialRemark"
                          :disabled="canDiable"
                          placeholder="请输入"
                          size="mini"
                        />
                      </template>
                    </el-table-column>
                    <el-table-column
                      v-if="!canDiable"
                      label="操作"
                      fixed="right"
                      show-overflow-tooltip
                      min-width="80"
                      align="center"
                    >
                      <template slot-scope="scope">
                        <el-tooltip
                          class="item"
                          effect="dark"
                          content="删除"
                          placement="right-start"
                        >
                          <span
                            class="pointer"
                            @click="purchaseDelete(scope.$index)"
                            ><i class="el-icon-delete"
                          /></span>
                        </el-tooltip>
                      </template>
                    </el-table-column>
                  </el-table>
                </div>
              </div>
            </div>
          </div>
          <div slot="footer" class="dialog-footer">
            <el-button v-if="opsid === 2" size="mini" @click="printLL"
              >打印领料单</el-button
            >
            <el-button size="mini" @click="isAddProduct = false"
              >取 消</el-button
            >
            <!-- 新增       -->
            <el-button
              v-if="opsid !== 2"
              :loading="addProductLoading"
              :disabled="addProductLoading"
              element-loading-spinner="el-icon-loading"
              type="primary"
              size="mini"
              @click="savell"
              >{{ btm }}</el-button
            >
          </div>
        </el-dialog>
        <SelectMateriaList
          ref="materiaList"
          :per-visible.sync="isSemidialog"
          :select-list="list"
          @getMateriListData="refuseListsAll"
        />
        <el-dialog
          append-to-body
          title="选择物料"
          :visible.sync="isSemidialog222"
          :close-on-click-modal="false"
          custom-class="bodyNoPadDialog bigDialog"
          width="70%"
          @close="closeSemiDialog"
          @open="openmater"
        >
          <div class="dialogDody marDialog flex flex_column">
            <div class="btnCon flex flex_end">
              <!-- 搜索框-->
              <div class="search">
                <el-input
                  v-model="SemiSearch.likeWords"
                  placeholder="输入关键字"
                  size="small"
                >
                  <el-button
                    slot="append"
                    :loading="marLoading"
                    type="primary"
                    icon="el-icon-search"
                    :disabled="marLoading"
                    element-loading-spinner="el-icon-loading"
                    @click="MarterdialogShow"
                  >
                    搜索
                  </el-button>
                </el-input>
              </div>
            </div>
            <!-- 表格区域       -->
            <div class="tableCon">
              <el-table
                :data="materialList"
                border
                style="width: 100%"
                @selection-change="handleSelectionChange"
              >
                <el-table-column prop="selection" width="55">
                  <el-table-column type="selection" width="55" />
                  <el-table-column prop="stockGoodsCode" label="物料编号" />
                  <el-table-column prop="stockGoodsName" label="物料名称" />
                  <el-table-column prop="specificationName" label="规格型号" />
                  <el-table-column prop="supplierName" label="供应商" />
                  <el-table-column prop="goodsCategoryName" label="物料类型" />
                  <el-table-column prop="stockQuantity" label="库存数量" />
                  <el-table-column prop="goodsUnitName" label="单位" />
                  <el-table-column
                    prop="groupName"
                    label="所属分组"
                  /> </el-table-column
              ></el-table>
            </div>
          </div>
          <div slot="footer" class="dialog-footer">
            <el-button size="mini" @click="isMarterdialog = false"
              >取 消</el-button
            >
            <!-- 选择订单 -->
            <el-button
              v-loading="addLoading"
              :disabled="addLoading"
              element-loading-spinner="el-icon-loading"
              type="primary"
              size="mini"
              @click="saveColorManuscript"
            >
              确定</el-button
            >
          </div>
        </el-dialog>
        <!-- 原因   -->
        <el-dialog
          title="作废原因"
          :visible.sync="isNopassshow"
          :close-on-click-modal="false"
          custom-class="comDialog"
          width="40%"
          @close="closePassDialog"
          append-to-body
        >
          <div class="dialogDody">
            <el-form ref="passForm" :model="passForm" class="dialogForm">
              <el-form-item class="mt12">
                <el-input
                  v-model="passForm.cancelReason"
                  prop="cancelReason"
                  type="textarea"
                  placeholder="请输入内容"
                  :autosize="{ minRows: 6 }"
                  size="mini"
                />
              </el-form-item>
            </el-form>
          </div>
          <span slot="footer" class="dialog-footer">
            <el-button size="mini" @click="isNopassshow = false"
              >取 消</el-button
            >
            <el-button
              :disabled="addLoading"
              element-loading-spinner="el-icon-loading"
              type="primary"
              size="mini"
              @click="passSave"
              >提交</el-button
            >
          </span>
        </el-dialog>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button size="mini" @click="isVisible = false">取 消</el-button>
      </div>
    </el-dialog>
    <rintLLT :product-from="prinftMass" />
  </div>
</template>
<script>
import SelectSCorder from "@/components/selectSCorder";
import perRedioDialog from "@/components/perDialogRedio";
import selectProductOrder from "@/components/selectProductOrder";
import SelectMateriaList from "@/components/selectMaterial";
import rintLLT from './printLLT.vue'
import { mapGetters } from "vuex";
import { string } from "yargs";
export default {
  name: "picking",
  props: {
    perVisible: {
      type: Boolean,
      required: false,
    },
    equipmentNo: {
      type: String,
      required: true,
    },
    produceTaskBillNo: {
      type: String,
      required: true,
    },
  },
  components: {
    SelectSCorder,
    perRedioDialog,
    SelectMateriaList,
    selectProductOrder,
    rintLLT
  },
  data() {
    return {
      isSemidialog222: false,
      ops: "add", // 操作、新建，修改，查看
      opsid: 1, // 3 确定 1 新建， 4 修改， 2 查看
      list: [],
      tableHeight: null, // 表格最大高度
      showOrder: false,
      isSeeMaterriel: false, // 查看弹框是否打开
      isAddMaterriel: false, // 新建弹框是否打开
      addMaterrielLoading: false, // 新建保存加载
      searchLoading: false, // 搜索加载效果
      allMaterirls: [], // 全部数据列表
      colorState: null,
      addLoading: false,
      selectRow: null,
      isNopassshow: false,
      equipmentList: [],
      passForm: {
        cancelReason: "",
      },
      prinftMass: {},
      // 表格操作
      ProductForm: {
        getMaterialType: 1,
        getMaterialPersonName: "",
        equipmentNo: "",
        mxDataList: [],
      },
      // 搜索条件
      search: {
        pageIndex: 1,
        pageSize: 30,
        likeWords: "",
      },
      total: 0, // 总条数
      tableHead: [], // 表格表头
      addProductLoading: false,
      isAddProduct: false,
      isperShow: false,
      isSemidialog: false,
      multipleSelection: null,
      purchaseInfoDatas: [{}],
      allSupliers: [],
      purchaseTypes: [
        {
          dicValueID: 0,
          dicValueDesc: "生产领料",
          dicValueCode: 1,
        },
        {
          dicValueID: 1,
          dicValueDesc: "生产补料",
          dicValueCode: 2,
        },
      ],
      SemiSearch: [],
      dataList: [],
      marLoading: false,
      canDiable: false,
      rules: {
        getMaterialPersonName: [
          { required: true, message: "请选择人员", trigger: "change" },
        ],
      },
      materialList: [], // 订单列表
      templateSelection: null,
      radio: "",
      materalSearch: {
        machineCode: "", //生产机台代码
        produceTaskBillNo: "", //生产任务单号
        likeWords: "",
      },

      query: {
        produceTaskBillNo: "",  //生产任务单号
        produceCraftNo: "", //生产工艺代码
      },

      radioSelect: null,
      marLoading: false,
      addLoading: false,
    };
  },
  computed: {
    ...mapGetters(["name", "userInfo"]),
    btm() {
      if (this.opsid === 3) {
        return "确认";
      } else {
        return "保存";
      }
    },
    tname() {
      if (this.opsid === 1) {
        return "新建生产领料单";
      } else if (this.opsid === 2) {
        return "查看生产领料单";
      } else if (this.opsid === 3) {
        return "确定生产领料单";
      } else if (this.opsid === 4) {
        return "修改生产领料单";
      } else {
        return "复制生产领料单";
      }
    },
    isVisible: {
      get() {
        return this.perVisible;
      },
      set(val) {
        this.$emit("update:perVisible", val);
      },
    },
  },
  watch: {
    perVisible(o, n) {
      if (o) {
        this.MarterdialogShow();
      }
    },
  },
  updated() {},
  created() {},
  mounted() {},
  methods: {
    opens() {
      this.materalSearch.likeWords = "";
      // this.MarterdialogShow()
    },
    closeMarDialog() {
      this.isVisible = false;
    },
    MarterdialogShow() {
      this.materalSearch.machineCode = this.equipmentNo;
      this.materalSearch.produceTaskBillNo = this.produceTaskBillNo;

      const parmas = this.materalSearch;
      this.marLoading = true;
      this.$api.product
        .GetMachinesProduceGetMaterialBillList(parmas)
        .then((res) => {
          this.dataList = res;
          this.marLoading = false;
        })
        .catch(() => {});
    },

    printLL() {
      const { mxDataList, ...basedata } = this.ProductForm;
      this.prinftMass = {
        mxDataList: mxDataList,
        basedata: basedata,
      };
      var printHtml = document.getElementById("print-iframe-ll").innerHTML;
      var wind = window.open(
        "",
        "newwindow",
        " top=100, left=100, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=n o, status=no"
      );
      wind.document.body.innerHTML = printHtml;
      wind.print();
    },
    closePassDialog() {
      this.passForm.cancelReason = "";
      this.selectRow = null;
    },

    checkProductList(row) {
      this.opsid = 2;
      this.canDiable = true;
      this.getDetail(row);
      // this.$router.push({
      //   path: '/business/orderDetail', // 跳转的路径
      //   query: {
      //     tabIndex: 4,
      //     saleOrderNo: row.saleOrderNo,
      //     lltype: '1'
      //   }
      // })
    },
    // 新建点击事件
    newAddClick() {
      // this.isAddProduct = true
      this.ops = "add";
      this.canDiable = false;
      this.opsid = 1;
      const parmas = {
        produceTaskBillNo:this.produceTaskBillNo
      }
      this.$api.product
        .GetProduceTaskBillsPartFileds(parmas)
        .then((res) => {
          if (res) {
            this.ProductForm = res;
            this.ProductForm.equipmentNo = this.equipmentNo;
            this.ProductForm.getMaterialPersonName = this.userInfo.employeeName
            this.ProductForm.getMaterialPerson = this.userInfo.employeeCode
            this.ProductForm.mxDataList = [];
            this.ProductForm.productCode = res.agreementNo
            this.ProductForm.productVersion = res.versionSurface
            this.isAddProduct = true;
          }
        })
        .catch(() => {});
    },
    handleClick(row) {
      this.opsid = 2;
      this.canDiable = true;
      this.getDetail(row);
    },
    handleConfirm(row) {
      this.opsid = 3;
      this.canDiable = true;
      this.getDetail(row);
    },
    handleDone(row) {
      this.selectRow = row;
      this.isNopassshow = true;
    },
    handleCopy(row) {
      this.opsid = 5;
      this.canDiable = false;
      this.openCp();

      const _data = {
        getMaterialID: row.getMaterialID,
        getMaterialBillNo: row.getMaterialBillNo,
      };
      this.$api.product.GetProduceMaterialBillDetail(_data).then((res) => {
        this.equipmentList.push({
          equipmentName: res.equipmentName,
          equipmentNo: res.equipmentNo,
        });
        delete res.baseData.getMaterialID;
        delete res.baseData.getMaterialBillNo;
        this.ProductForm = res.baseData;
        this.ProductForm.mxDataList = res.mxDataList;
        this.isAddProduct = true;
      });
    },
    handleUpdata(row) {
      this.opsid = 4;
      this.canDiable = false;
      this.getDetail(row);
    },
    passSave() {
      const _data = {
        getMaterialID: this.selectRow.getMaterialID,
        cancelReason: this.passForm.cancelReason,
      };
      this.$api.product
        .CancelGetProduceMaterialBill(_data)
        .then(() => {
          this.MarterdialogShow();
          this.isNopassshow = false;
          this.addLoading = false;
          this.$message({
            message: "作废成功",
            type: "success",
          });
        })
        .catch(() => {});
    },
    handleDelete(row) {
      const _data = {
        getMaterialID: row.getMaterialID,
      };
      this.$confirm("确定删除?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        this.$api.product
          .DeleteGetProduceMaterialBill(_data)
          .then(() => {
            this.MarterdialogShow();
            this.$message({
              message: "删除成功",
              type: "success",
            });
          })
          .catch(() => {});
      });
    },
    getDetail(row) {
      console.log(row);
      const _data = {
        getMaterialID: row.getMaterialID,
        getMaterialBillNo: row.getMaterialBillNo,
      };
      this.$api.product.GetProduceMaterialBillDetail(_data).then((res) => {
        this.equipmentList.push({
          equipmentName: res.equipmentName,
          equipmentNo: res.equipmentNo,
        });
        this.ProductForm = res.baseData;
        this.ProductForm.productVersion =
          res.baseData.printingSurface + res.baseData.productVersion;
        this.ProductForm.mxDataList = res.mxDataList;
        this.prinftMass = res;
        this.isAddProduct = true;
      });
    },
    selectCurrentRow(row) {
      this.ops = "add";
      this.isAddProduct = true;
      this.ProductForm.produceTaskBillNo = row.produceTaskBillNo;
      this.ProductForm.saleOrderNo = row.saleOrderNo;

      this.ProductForm.productCode = row.productCode;
      this.ProductForm.customerBillNo = row.customerBillNo;
      this.ProductForm.orderProductName = row.orderProductName;
      this.ProductForm.productVersion =
        row.printingSurface + row.orderProductVersion;
    },
    purchaseDelete(index) {
      this.ProductForm.mxDataList.splice(index, 1);
    },
    // 选择物料
    openmater() {
      const _data = {
        produceTaskBillNo: this.ProductForm.produceTaskBillNo,
        likeWords: "",
      };
      this.$api.product.GetProduceTaskMaterialList(_data).then((res) => {
        res.forEach((v) => {
          v.goodsCategoryName = v.categoryName;
          v.planUseQuantity = v.planMaterialQuantity;
        });
        this.materialList = res;
      });
    },
    openCp() {
      const _data = {
        produceTaskBillNo: this.ProductForm.produceTaskBillNo,
        likeWords: "",
      };
      this.$api.product.GetProduceTaskEquipmentList(_data).then((res) => {
        this.equipmentList = res;
      });
    },
    savell() {
      if (this.ProductForm.mxDataList.length < 1) {
        this.$message.warning("请添加领料明细");
        return;
      }
      if (this.opsid === 3) {
        const _data3 = {
          getMaterialID: this.ProductForm.getMaterialID,
        };
        this.$api.product
          .SureGetProduceMaterialBill(_data3)
          .then(() => {
            this.addProductLoading = false;
            this.isAddProduct = false;
            this.MarterdialogShow();
            this.$message({
              message: "确认成功",
              type: "success",
            });
          })
          .catch(() => {
            this.addProductLoading = false;
          });
      } else if (this.opsid === 4) {
        const parmas = this.ProductForm;
        this.$refs.ProductForm.validate((valid) => {
          if (valid) {
            this.addProductLoading = true;
            this.$api.product
              .UpdateGetProduceMaterialBill(parmas)
              .then(() => {
                this.addProductLoading = false;
                this.isAddProduct = false;
                this.MarterdialogShow();
                this.$message({
                  message: "修改成功",
                  type: "success",
                });
              })
              .catch(() => {
                this.addProductLoading = false;
              });
          }
        });
      } else {
        const parmas = this.ProductForm;
        this.$refs.ProductForm.validate((valid) => {
          if (valid) {
            this.addProductLoading = true;
            this.$api.product
              .CreateGetProduceMaterialBill(parmas)
              .then(() => {
                this.addProductLoading = false;
                this.isAddProduct = false;
                this.MarterdialogShow();
                this.$message({
                  message: "保存成功",
                  type: "success",
                });
              })
              .catch(() => {
                this.addProductLoading = false;
              });
          }
        });
      }
    },

    // 得到申请人员
    getEmployee(val) {
      this.ProductForm.getMaterialPersonName = val.employeeName;
      this.ProductForm.getMaterialPerson = val.employeeCode;
    },
    supplierChange(val) {
      // this.materSearch.supplierCode = val
      // this.purchaseInfoDatas = []
    },
    closeSemiDialog() {
      this.isSemidialog = false;
    },
    handleSelectionChange(val) {
      val.forEach((res) => {
        res.goodsCategoryName = res.categoryName;
        res.planUseQuantity = res.planMaterialQuantity;
      });
      this.multipleSelection = val;
    },
    saveColorManuscript() {
      const array = JSON.parse(JSON.stringify(this.ProductForm.mxDataList));
      const arr = JSON.parse(JSON.stringify(this.multipleSelection));
      arr.forEach((item) => {
        item.applyGetQuantity = item.planUseQuantity;
        item.produceMaterialNo = item.goodsCode;
        item.getMaterialRemark = "";
      });
      this.ProductForm.mxDataList = arr.reduce((result, item) => {
        const val = result.some(
          ({ stockGoodsCode }) => stockGoodsCode === item.stockGoodsCode
        );
        if (!val) {
          result.push(item);
        }
        return result;
      }, array);
      this.closeSemiDialog();
    },
    // 选择材料后刷新
    refuseListsAll(selectArr) {
      console.log(selectArr)
      const array = JSON.parse(JSON.stringify(this.ProductForm.mxDataList));
      const arr = JSON.parse(JSON.stringify(selectArr));
      arr.forEach((item) => {
        item.goodsCategoryName = item.categoryName;
        item.produceMaterialNo = item.goodsCode;
        item.applyGetQuantity = 0;
        item.stockQuantity = item.stockSumQuantity;
        item.getMaterialRemark = "";
      });
      console.log(this.ProductForm.mxDataList)
      this.ProductForm.mxDataList = arr.reduce((result, item) => {
        const val = result.some(
          ({ stockGoodsCode }) => stockGoodsCode === item.stockGoodsCode
        );
        if (!val) {
          result.push(item);
        }
        return result;
      }, array);
      console.log(this.ProductForm.mxDataList)
      this.closeSemiDialog();
    },
    // 详情
    getMaterielInfo(id) {},
    // 保存表头样式变化
    saveHead(newArray) {
      const parmas = newArray;
      setTimeout(() => {
        this.$api.common.saveTableStyle(parmas).then(() => {});
      }, 300);
    },
    // 保存表头列宽度
    surverWidth(newWidth, oldWidth, column) {
      setTimeout(() => {
        const heads = [...this.tableHead];
        heads.forEach((item) => {
          if (item.columnCode === column.property) {
            item.columnWidth = column.width;
            return;
          }
        });
        this.saveHead(heads);
      }, 100);
    },
    // 表格最大高度
    calHeight() {
      this.$nextTick(() => {
        const rect = this.$refs.tableCon.getBoundingClientRect();
        this.tableHeight = rect.height;
      });
    },
    // 获取表格表头
    getTableHead() {
      const parmas = {
        tableCode: this.$config.producegetmaterialbilllist,
      };
      this.$api.common.getAllTableHead(parmas).then((res) => {
        console.log(res);
        res.sort(arraySort("columnSort"));
        this.tableHead = res;
      });
    },
    // 新建弹框关闭事件
    closeDialog() {
      if (this.$refs.ProductForm) {
        this.$refs.ProductForm.resetFields();
      }
      this.ProductForm = this.$options.data().ProductForm;
    },
  },
};
</script>
<style lang="scss" scoped>
.container {
  height: 100%;
}
.permangeRg {
  border: 1px solid #e6e6e6;
  background: #fff;
  height: 100%;

  .mainTT {
    font-size: 16px;
    font-weight: bold;
    width: 100%;
    padding: 18px 16px;
    padding-bottom: 0;
  }
}
.addWuliaoBox {
  padding: 10px 16px;

  .tableBox {
    margin-top: 16px;
    border: 1px solid #e6e6e6;
    border-bottom: none;
    border-radius: 8px 8px 0 0;
    overflow: hidden;

    .tt {
      height: 38px;
      line-height: 38px;
      padding-left: 16px;
      background: #f7f8fa;
      border-radius: 8px 8px 0 0;
    }
  }
}

.subTip {
  border-bottom: 1px #e6e6e6 solid;
  background: #f5f6f9;
  padding: 8px 16px;
}
</style>
